home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / edit / aurora2.zip / EXT.AML < prev    next >
Text File  |  1995-01-26  |  73KB  |  2,794 lines

  1.  
  2. // ───────────────────────────────────────────────────────────────────
  3. // The Aurora Editor v2.0
  4. // Copyright 1993-1995 nuText Systems. All Rights Reserved Worldwide.
  5. //
  6. // Editor library extensions (included by MAIN.AML)
  7. //
  8. // *You should be very familiar with AML before making changes here*
  9. // If you have made any changes, save this file and select 'Recompile
  10. // the Editor' <alt f2> from the Set menu. Exit and re-enter the
  11. // editor for your changes to take effect.
  12. // ───────────────────────────────────────────────────────────────────
  13.  
  14. // ───────────────────────────────────────────────────────────────────
  15. //  All windows
  16. // ───────────────────────────────────────────────────────────────────
  17.  
  18.   object  a
  19.  
  20.     // get the drive and path portion of a filespec
  21.     function  getpath (file)
  22.       return  file [1 : pos "\\" file 'r']
  23.     end
  24.  
  25.     // get the name and extension portion of a filespec
  26.     function  getname (file)
  27.       return  file [(pos "\\" file 'r') + 1 : 0]
  28.     end
  29.  
  30.     // get the extension portion of a filespec
  31.     function  getext (file)
  32.       p = pos '.' file 'r'
  33.       if? p file [p : TO_END]
  34.     end
  35.  
  36.     // append a default extension for filenames that don't have one
  37.     function  defext (file extension)
  38.       if pos '.' file then
  39.         file
  40.       else
  41.         file + '.' + extension
  42.       end
  43.     end
  44.  
  45.     // force a filename to have an extension
  46.     function  forceext (file ext)
  47.       p = pos '.' file 'r'
  48.       return (if? p  file [1 : p]  file + '.') + ext
  49.     end
  50.  
  51.     // generate <shiftdown>, <shiftup> events from raw <shiftkey> event
  52.     function  <shiftkey> (newstate oldstate)
  53.       send ( if newstate & 3 and not (oldstate & 3) then
  54.                "shiftdown"
  55.              elseif oldstate & 3 and not (newstate & 3) then
  56.                "shiftup"
  57.              end )
  58.     end
  59.  
  60.     // generate multi-key events
  61.     function  prefix (keycode)
  62.       keyname = locase (getkeyname keycode)
  63.       say  keyname + "<more...>"
  64.       keyname2 = locase (getkeyname (getkey))
  65.       queue  keyname + keyname2
  66.       // allow the <ctrl> key to be held down...
  67.       if keyname  [1:5] == "<ctrl" and keyname2 [1:5] == "<ctrl" then
  68.         queue   keyname + '<' + keyname2 [7 : TO_END]
  69.       end
  70.       display
  71.     end
  72.  
  73.     // repeat keys for a user-specified number of times
  74.     function  askrepkey
  75.       var keystring
  76.       var i
  77.       say "Enter keys to repeat, then <esc>:"
  78.       hidecursor
  79.       keycode = getkey
  80.       while keycode <> <esc> do
  81.         keystring = keystring + (char2 keycode)
  82.         keycode = getkey
  83.       end
  84.       if keystring then
  85.         count = ask "Number of repetitions"
  86.         if count then
  87.           strlen = sizeof keystring
  88.           while count do
  89.             j = 1
  90.             while j < strlen do
  91.               queuekey (bin2int keystring [j : 2])
  92.               j = j + 2
  93.             end
  94.             repeat
  95.               dispatch
  96.             until not event?
  97.             count = count - 1
  98.           end
  99.         end
  100.       end
  101.     end
  102.  
  103.     // a simple file picklist
  104.     function  picklist (filespec title)
  105.       filespec = qualify filespec (getbufname)
  106.       repeat
  107.         filespec = askfile filespec  filespec + title _FmgrSort _FmgrOpt
  108.       until not (filespec and (dir? filespec))
  109.       return filespec
  110.     end
  111.  
  112.     // execute a fully qualified DOS program
  113.     // (saving and restoring the current path)
  114.     function  os (program options)
  115.       cp = getcurrpath
  116.       currpath (getpath (getbufname))
  117.       r = exec program options
  118.       currpath cp
  119.       return r
  120.     end
  121.  
  122.     // shell to DOS by executing COMMAND.COM
  123.     function  shell
  124.       os (getenv "COMSPEC") "ch"
  125.     end
  126.  
  127.     // execute DOS commands, programs, and .bat files
  128.     function  run (file options)
  129.       if file then
  130.         os (getenv "COMSPEC") + " /c " + file  options
  131.       else
  132.         shell
  133.       end
  134.     end
  135.  
  136.     // execute DOS commands or programs and capture the output
  137.     // via DOS piping (will not capture .bat file output)
  138.     function  runcap (command options)
  139.       _cap = _cap + 1
  140.       capfile = qualify  "capture." + _cap  (getbufname)
  141.       run  command + '>' + capfile  options
  142.       open capfile
  143.       deletefile capfile
  144.     end
  145.  
  146.     // translate an AML compiler error code to an error message
  147.     function  errormsg (error)
  148.       case error
  149.         when 1001  "Can't open file"
  150.         when 1002, 1003  "Read error"
  151.         when 1004  "Not an executable macro file"
  152.         when 1031  "Write error"
  153.         when 1032  "Can't open compiler output file"
  154.         when 1101  "No closing quote"
  155.         when 1102  "No closing bracket"
  156.         when 1103  "Invalid symbol"
  157.         when 1104  "Invalid key or event"
  158.         when 1301  "No terminator"
  159.         when 1302  "Unexpected end of source"
  160.         when 1303  "No closing parenthesis"
  161.         when 1310  "Unexpected argument"
  162.         when 1311  "Unexpected terminator"
  163.         when 1312  "Unexpected function"
  164.         when 1313  "Unexpected operator"
  165.         when 1319  "Identifier '" + (geterror 's') + "' not defined"
  166.         when 1320  "Bad assignment"
  167.         when 1330  "Bad when clause"
  168.         when 1336  "Improperly placed break"
  169.         when 1337  "Invalid reference"
  170.         when 1501  "Can't open include file " + (geterror 's')
  171.         when 1502  "Include level exceeded"
  172.         when 1503  "Can't include compiled file in expression"
  173.         when 1504  "Include must be at top level"
  174.         when 1505  "Define can't be nested"
  175.         when 1506  "Function must be at top level"
  176.         when 1507  "Can't redefine builtin function"
  177.         when 1508  "Duplicated function argument"
  178.         when 1509  "Object statement not permitted"
  179.         when 1701  "Too many variables"
  180.         when 1702  "Too many function arguments"
  181.         when 1703  "Function or expression too large"
  182.         when 1704, 1705, 1707   "Internal stack overflow"
  183.         when 1706  "Out of symbol space"
  184.         otherwise "Fatal compilation error " + error
  185.       end
  186.     end
  187.  
  188.     // compile a macro with error messages
  189.     // the cursor is moved to any syntax errors
  190.     function  compilemacro2 (source dest msg)
  191.       if not source then
  192.         source = getbufname
  193.       end
  194.       say (if? msg msg "Compiling...")
  195.       source = qualify (defext source "aml") (getbufname)
  196.       error = compilemacro source (if? dest dest (forceext source 'x'))
  197.  
  198.       if error then
  199.  
  200.         // get additional error info
  201.         column = geterror 'k'
  202.         line = geterror 'l'
  203.         file = geterror 'f'
  204.  
  205.         // translate error code to an error message
  206.         msg = errormsg error
  207.  
  208.         // position the cursor to the error
  209.         if error <> 1001 and (open file) then
  210.           gotopos column line
  211.           send "onfound"
  212.         end
  213.  
  214.         // display the error
  215.         msgbox  file + " (line " + line + ", col " + column + "): " + msg
  216.                 "Error!" 'b'
  217.       else
  218.         say "Done."
  219.       end
  220.  
  221.       return error
  222.     end
  223.  
  224.     // regenerate the editor boot macro (a.x)
  225.     function  regen (msg)
  226.       dest = bootpath "main.x"
  227.       error = compilemacro2 (bootpath "main.aml") dest msg
  228.       if not error then
  229.         bootfile = bootpath "a.x"
  230.         deletefile bootfile
  231.         renamefile dest bootfile
  232.       end
  233.       return error
  234.     end
  235.  
  236.     // regenerate the editor boot macro (a.x) with a message
  237.     function  recompile
  238.       if not regen then
  239.         msgbox "Exit and re-enter for changes to take effect. "
  240.       end
  241.     end
  242.  
  243.     // regenerate the editor boot macro (a.x) with a message,
  244.     // and integrate current config variables in compilation
  245.     function  saveconfig
  246.       configx = bootpath "config.x"
  247.       saveobject "prf" configx
  248.       regen "Saving..."
  249.       deletefile configx
  250.     end
  251.  
  252.     // load and run a compiled macro file
  253.     function  includemacro2 (macrofile)
  254.       includemacro (qualify (forceext
  255.                  (if? macrofile macrofile (getbufname)) 'x') (getbufname))
  256.     end
  257.  
  258.     // load, run, and discard a compiled macro file
  259.     function  runmacro2 (macrofile)
  260.       runmacro (qualify (forceext
  261.                  (if? macrofile macrofile (getbufname)) 'x') (getbufname))
  262.     end
  263.  
  264.     // send a string to the default printer device
  265.     function  printstr (string)
  266.       if string then
  267.         fileid = openfile _PrtDev 'w'
  268.         if fileid then
  269.           writefile fileid string
  270.           closefile fileid
  271.         end
  272.       end
  273.     end
  274.  
  275.     // open a new file
  276.     function  opennew (file options)
  277.       prevbufname = getbufname
  278.       buffer = createbuf
  279.       if buffer then
  280.         setbufname (qualify (if? file file "NEW.TXT") prevbufname)
  281.         openbuf buffer options
  282.       end
  283.     end
  284.  
  285.     // toggle the video mode between 80x25 and 80x50
  286.     function  togglemode
  287.       videomode 80 (if? getvidrows == 25  50 25)
  288.     end
  289.  
  290.  
  291.     // search/replace with verification
  292.     // (returns the number of replacements made)
  293.     function  replver (searchstr replstr options)
  294.  
  295.       var title
  296.       var count
  297.  
  298.       repeat
  299.         length = find searchstr options
  300.         if length then
  301.  
  302.           if not title then
  303.             title = gettitle
  304.             settitle  "Replace (Yes/No/All/One/Reverse/Undo/Quit)? "
  305.             // remove global for next find
  306.             options = sub 'g' '' options
  307.           end
  308.  
  309.           send "onfound" length
  310.  
  311.           // get keycode and convert to lower case
  312.           p = getkey | 020h
  313.           case p
  314.  
  315.             when <y>, <o>, <a>
  316.               undobegin
  317.               l = (replace searchstr replstr  (sub 'r' '' options) + "*z") - 1
  318.               if not (pos 'r' options) then
  319.                 right l
  320.               end
  321.               count = count + 1
  322.               if p <> <y> then
  323.                 length = ''
  324.                 if p == <a> then
  325.                   count = count + (replace searchstr replstr  options + "az")
  326.                 end
  327.               end
  328.               undoend
  329.  
  330.             when <u>
  331.               if count then
  332.                 undo
  333.                 count = count - 1
  334.                 if pos 'r' options then
  335.                   right 1
  336.                 else
  337.                   if getcol == 1 then
  338.                     if up then
  339.                       col 16000
  340.                     end
  341.                   else
  342.                     left l
  343.                   end
  344.                 end
  345.               end
  346.  
  347.             when <n>
  348.                // do nothing
  349.  
  350.             when <r>
  351.                options = if? (pos 'r' options) (sub 'r' '' options)  options + 'r'
  352.  
  353.             otherwise
  354.               if not count then
  355.                 count = '0'
  356.               end
  357.               break
  358.           end
  359.         end
  360.       until not length
  361.  
  362.       if title then
  363.         settitle title
  364.       end
  365.  
  366.       return count
  367.     end
  368.  
  369.  
  370.     // search for a multi-string search argument
  371.     function  search (searchstr reverse rep refopt refrepl)
  372.  
  373.       var replstr
  374.       var options
  375.  
  376.       // split up search multi-string
  377.       if pos '/' searchstr then
  378.         n = splitstr '' searchstr  ref searchstr  ref replstr  ref options
  379.         if n > 1 then
  380.           if n == 2 then
  381.             options = replstr
  382.             replstr = ''
  383.             // case sensitive
  384.             if not options then
  385.               options = 'c'
  386.             end
  387.           end
  388.         end
  389.       end
  390.  
  391.       if searchstr then
  392.  
  393.         // default options
  394.         if not options then
  395.           options = _SearchOpt
  396.           if n > 2 then
  397.             options = options + _ReplaceOpt
  398.           end
  399.         end
  400.  
  401.         // reverse search direction if specified
  402.         if reverse then
  403.           options = if pos 'r' options then
  404.                       sub 'r' '' options
  405.                     else
  406.                       options + 'r'
  407.                     end
  408.         end
  409.  
  410.         // remove global for repeat find
  411.         if rep and (pos 'g' options) then
  412.           options = sub 'g' '' options
  413.         end
  414.  
  415.         // return values for calling function to check
  416.         refopt  = options
  417.         refrepl = n >= 3
  418.  
  419.         // resurface marked window for block search
  420.         if pos 'b' options then
  421.           buffer = getmarkbuf
  422.           if buffer and buffer <> getcurrbuf then
  423.             currwin (getcurswin (getcurrcurs buffer))
  424.           end
  425.         end
  426.  
  427.         // search and replace
  428.         if n >= 3 then
  429.  
  430.           // do the replace
  431.           if pos 'a' options then
  432.             replace searchstr replstr options
  433.           else
  434.             replver searchstr replstr options
  435.           end
  436.  
  437.         // search only
  438.         else
  439.           find searchstr options
  440.         end
  441.       end
  442.     end
  443.  
  444.     // hot key for file mgr and file picklists
  445.     function onhotkey (character)
  446.       searchstr = '^[~]' + (upcase character)
  447.       if find searchstr 'x' then
  448.         adjustrow getviewrows / 3
  449.         return
  450.       else
  451.         line = getrow
  452.         gotopos 1 1
  453.         if find searchstr 'x' then
  454.           adjustrow getviewrows / 3
  455.           return
  456.         end
  457.         // not found
  458.         beep 320 70
  459.         row line
  460.       end
  461.     end
  462.  
  463.  
  464.   object  mon
  465.  
  466.     // erase key macros
  467.     function  erasekey2 (options)
  468.       if erasekey options then
  469.         _kd = TRUE
  470.         display
  471.         say (if? (pos options 'a') "All keys macros erased"
  472.                                    "Scrap key macro erased")
  473.       end
  474.     end
  475.  
  476.     // toggle the key macro record mode
  477.     function  record
  478.       if not playing? then
  479.         _kd = TRUE
  480.         if not setting? 'R' then
  481.           erasekey
  482.           record_on = TRUE
  483.         end
  484.         setting 'R' TOGGLE
  485.         say "Record" + (if? record_on "ing..." " OFF")
  486.       end
  487.     end
  488.  
  489.     // play a key macro
  490.     function  play (keymacro)
  491.       setdisplay OFF
  492.       if not (playkey keymacro) then
  493.         say "No key macro to play." 'b'
  494.       end
  495.       setdisplay ON
  496.     end
  497.  
  498.  
  499. // ───────────────────────────────────────────────────────────────────
  500. //  Edit windows and File Manager windows
  501. // ───────────────────────────────────────────────────────────────────
  502.  
  503.   object  edit_fmgr
  504.  
  505.     // close all windows
  506.     function  closeall (options)
  507.       setxobj "__G" ON 'a'
  508.       begdesk
  509.       while getwincount and (send "close" options) end
  510.       enddesk
  511.       setxobj "__G" OFF 'a'
  512.     end
  513.  
  514.     // move the cursor to any edge of a mark
  515.     function  gotomark (options)
  516.       if mark? then
  517.  
  518.         window = getcurswin (getcurrcurs (getmarkbuf))
  519.         if window then
  520.           currwin window
  521.         end
  522.  
  523.         // left or right
  524.         if pos 'l' options then
  525.           col (getmarkleft)
  526.         elseif pos 'r' options then
  527.           col (getmarkright)
  528.         end
  529.  
  530.         // top or bottom
  531.         if pos 't' options then
  532.           row (getmarktop)
  533.         elseif pos 'b' options then
  534.           row (getmarkbot)
  535.         end
  536.  
  537.         if window then
  538.           send "onfound"
  539.         end
  540.  
  541.       else
  542.         say "Block not found" 'b'
  543.       end
  544.     end
  545.  
  546.     // goto a bookmark with message
  547.     function  gotobook2 (bookmark)
  548.       msg = "Bookmark '" + bookmark + "'"
  549.       if gotobook bookmark then
  550.         window = getcurswin (getcurrcurs (getbookbuf bookmark))
  551.         if window <> getcurrwin then
  552.           currwin window
  553.         end
  554.         display
  555.         say msg
  556.       else
  557.         say msg + " not found"  'b'
  558.       end
  559.     end
  560.  
  561.     // prompt to goto a bookmark
  562.     function  askbook (msg)
  563.       askx (if? msg msg "Bookmark Name") "_book" "gotobook2"
  564.     end
  565.  
  566.     // cycle though all existing bookmarks
  567.     function  cyclebook
  568.       repeat
  569.         l = _lb
  570.         bookmark = if? l (getprevbook l) (getcurrbook)
  571.         buffer = getcurrbuf
  572.         while not bookmark and buffer do
  573.           buffer = getprevbuf buffer
  574.           bookmark = getcurrbook buffer
  575.         end
  576.         _lb = bookmark
  577.       until bookmark or not l
  578.       gotobook2 bookmark
  579.     end
  580.  
  581.     // print the current buffer or mark
  582.     function  print (options)
  583.       printstr _PrtIni
  584.       header = _PrtHdr
  585.       if not (posnot ' ' header) or (dir? (getbufname)) then
  586.         date = getdate
  587.         header = getbufname + "   (" + date [posnot ' ' date : TO_END] +
  588.                                  ' ' + gettime + ')'
  589.       end
  590.       if not ( if pos 'b' options  then printblock _PrtDev header ''
  591.                 else    printbuf _PrtDev header end ) then
  592.         say "Print failed" 'b'
  593.       end
  594.     end
  595.  
  596.     // replace/append/cancel or ok/cancel menus
  597.     function  askrac (file menuname)
  598.       if _ConRpl == 'y' and (locatefile file) then
  599.         locase (popup (if? menuname menuname "rac" )
  600.                         file + " Exists" +
  601.                         (if? menuname == "ok" ". Replace?")) [1]
  602.       else
  603.         'r'
  604.       end
  605.     end
  606.  
  607.     // generic prompt to change a configuration variable
  608.     function  askc (pstring variable history)
  609.       newvalue = ask pstring history (lookup variable "prf")
  610.       if newvalue then
  611.         setxobj variable newvalue "prf"
  612.       end
  613.     end
  614.  
  615.     // prompts to change specific configuration variables
  616.     function  askbinary  askc "Binary Line Length"  "BinaryLength"     end
  617.     function  askdelim   askc "Line Delimiter String in Hex" "LineDlm" end
  618.     function  asktabw    askc "Tab Width"      "TabWidth"    end
  619.     function  asktabv    askc "Variable Tabs"  "VarTabs"     end
  620.     function  asklmarg   askc "Left Margin"    "LMargin"     end
  621.     function  askrmarg   askc "Right Margin"   "RMargin"     end
  622.     function  askclip    askc "Clipboard Name" "ClipName"    end
  623.     function  askprthdr  askc "Current Header/Footer" "PrtHdr" end
  624.  
  625.     // generic prompt with command execution
  626.     function  askx (pstring history func parm2)
  627.       parm1 = ask pstring history
  628.       if parm1 then
  629.         send func parm1 parm2
  630.         if history then
  631.           addhistory history parm1
  632.         end
  633.         return 1
  634.       end
  635.     end
  636.  
  637.     // open prompt
  638.     function  askopen
  639.       file = ask "[file/ibcenz] Open" "_load"
  640.       if file then
  641.         // addhistory not needed for open
  642.         open file
  643.       end
  644.     end
  645.  
  646.     // open binary prompt
  647.     function  askopenb
  648.       askx "File to open in Binary Mode" "_load" "open" 'b'
  649.     end
  650.  
  651.     // macro expression prompt
  652.     function  askeval
  653.       if askx "Macro Expression" "_cmd" "eval" then
  654.         error = geterror 'c'
  655.         if error then
  656.           msgbox "Expression column " + (geterror 'k') +
  657.                  ": " + (errormsg error)  "Error" 'b'
  658.         end
  659.       end
  660.     end
  661.  
  662.     // prompt to include a macro
  663.     function  askimacro
  664.       askx "Include Macro File"  "_load" "includemacro2"
  665.     end
  666.  
  667.     // prompt to run a macro
  668.     function  askrmacro
  669.       askx "Run Macro File"  "_load" "runmacro2"
  670.     end
  671.  
  672.     // prompt to compile a macro
  673.     function  askcmacro
  674.       askx "Compile Macro File"  "_load" "compilemacro2"
  675.     end
  676.  
  677.     // macro picklist
  678.     function  pickmacro
  679.       macro = askfile getbootpath + "MACRO\\*.X" "Select a macro to run"
  680.                       _FmgrSort _FmgrOpt "maclist"
  681.       if macro then
  682.         runmacro macro
  683.       end
  684.     end
  685.  
  686.     // DOS command prompt
  687.     function  askrun
  688.       askx "DOS Command" "_os" "run" "ck"
  689.     end
  690.  
  691.     // prompt to capture DOS output
  692.     function  askruncap
  693.       askx "Capture DOS Output" "_os" "runcap" 'c'
  694.     end
  695.  
  696.     // open key macro file with messages
  697.     function  openkey2 (file)
  698.       if openkey file then
  699.         say (getname file) + " loaded"
  700.       else
  701.         say "Load failed" 'b'
  702.       end
  703.     end
  704.  
  705.     // prompt to open a key macro file
  706.     function  askopenkey
  707.       file = ask "Key macro filename" "_load"
  708.       if file then
  709.         openkey2 (qualify (defext file "mac") (getbufname))
  710.       end
  711.     end
  712.  
  713.     // prompt to save current key macros
  714.     function  asksavekey
  715.       file = ask "Save current key macros as" "_load"
  716.       if file then
  717.         file = qualify (defext file "mac") (getbufname)
  718.         if pos (askrac file "ok") "or" 'i' then
  719.           if not savekey file then
  720.             say "Save failed" 'b'
  721.           end
  722.         end
  723.       end
  724.     end
  725.  
  726.     // search files for a string in multi-string format with msgs
  727.     function  searchfiles (s)
  728.       var searchstr
  729.       var filespec
  730.       var options
  731.       n = splitstr '' s  ref searchstr  ref filespec  ref options
  732.       if n < 3 then
  733.         options = _SearchOpt
  734.         if n < 2 then
  735.           filespec = '.'
  736.         end
  737.       end
  738.       if searchstr then
  739.         r = scanfiles filespec searchstr options
  740.         if r <= 0 then
  741.           say (if? r filespec s) + " not found" 'b'
  742.         else
  743.           addhistory "_find" (joinstr '' searchstr options)
  744.         end
  745.       end
  746.     end
  747.  
  748.     // prompt to scan files for a string
  749.     function  askscan
  750.       scanstring = if _PromptStyle == 'd' then
  751.                      scandlg
  752.                    else
  753.                      ask "[string/files/iwx] Scan" "_scan"
  754.                    end
  755.       if scanstring then
  756.         searchfiles scanstring
  757.         addhistory "_scan" scanstring
  758.       end
  759.     end
  760.  
  761.     // reload the current file from disk
  762.     function  reopen (file)
  763.       open (if? file file getbufname) 'r'
  764.     end
  765.  
  766.     // open last file or directory
  767.     function  openlast
  768.       file = gethiststr "_load"
  769.       if file then
  770.         open file
  771.       end
  772.     end
  773.  
  774.     // open an AML configuration file in boot directory
  775.     function  opencfg (file)
  776.       open (bootpath  file + ".aml")
  777.     end
  778.  
  779.     // quick reference help
  780.     function  quickref (options openopt)
  781.       quickfile = getbootpath + (if? options <> 'o' "DOC\\") +
  782.                     case options [1]
  783.                       when 'l'  "LANGUAGE.DOX"
  784.                       when 'f'  "FUNCTION.DOX"
  785.                       when 'q'  "QUICKFUN.DOX"
  786.                       when 'o'  "ORDERFRM.DOC"
  787.                       when 't'  "TIPS.DOX"
  788.                       otherwise "USER.DOX"
  789.                     end
  790.       if (wintype? "edit") and (pos 'w' options) then
  791.         wordstr = send "getword" "a-zA-Z0-9?"
  792.       end
  793.       open quickfile openopt
  794.       if wordstr then
  795.         gotopos 1 1
  796.         // find string in reference
  797.         if find (char 0ffh) + wordstr + (char 0ffh) then
  798.           right
  799.           send "onfound" (sizeof wordstr)
  800.         // not found? then try function header in EXT.AML
  801.         elseif poschar 'fq' options then
  802.           close
  803.           ext = bootpath "EXT.AML"
  804.           closeit = _MultCopy == 'n' and not (findbuf ext)
  805.           open ext openopt
  806.           gotopos 1 1
  807.           n = find "function #" + wordstr  'x'
  808.           if n then
  809.             send "onfound" n
  810.           // still not found? then go back to reference
  811.           else
  812.             if closeit then
  813.               close
  814.             end
  815.             open quickfile openopt
  816.           end
  817.         end
  818.       end
  819.     end
  820.  
  821.     // popup menu to change the default prompt style
  822.     function  askprompt
  823.       menu "prompts"
  824.         item " &Command line" 1
  825.         item " &One-line box" 2
  826.         item " &Two-line box" 3
  827.         item " &Dialog box"   4
  828.       end
  829.       newtype = popup (getcurrbuf) "Select a Prompt Style" 25
  830.       if newtype then
  831.         setobj _PromptStyle "c12d" [newtype] "prf"
  832.       end
  833.       destroybuf "prompts"
  834.     end
  835.  
  836.  
  837. // ───────────────────────────────────────────────────────────────────
  838. //  Prompts and Edit windows
  839. // ───────────────────────────────────────────────────────────────────
  840.  
  841.   object  prompt
  842.  
  843.     // support for cua-style <shift> key marking
  844.     function  smark
  845.       if shiftkey? then
  846.         if _shfx then
  847.           undobegin
  848.           destroymark
  849.           markstream _shfx _shfx _shfy _shfy
  850.           _shfx = ''
  851.           _shfy = ''
  852.         end
  853.         extendmark
  854.       end
  855.     end
  856.  
  857.     // set anchor for shift-key marking
  858.     function  shiftdown
  859.       _shfx = getcol
  860.       _shfy = getrow
  861.       pass
  862.     end
  863.  
  864.     // end shift-key mark
  865.     function  shiftup
  866.       stopmark
  867.       pass
  868.       undoend
  869.     end
  870.  
  871.     // backspace in a prompt
  872.     function  backsp
  873.       if getcol > 1 then
  874.         left
  875.         delchar
  876.       end
  877.     end
  878.  
  879.     // get the word at the cursor
  880.     function  getword (charset column mark)
  881.       if not column then
  882.         column = getcol
  883.       end
  884.       if column <= getlinelen then
  885.         if not charset then
  886.           charset = _CSet
  887.         end
  888.         b = posnot charset (gettext column)
  889.         if b <> 1 then
  890.           b = if? b  column + b - 2  getlinelen
  891.           a = posnot charset (gettext 1 column) 'r'
  892.           a = if? a  a + 1  1
  893.           if mark then
  894.             undobegin
  895.             destroymark
  896.             markchar a b
  897.             undoend
  898.           else
  899.             gettext a  b - a + 1
  900.           end
  901.         end
  902.       end
  903.     end
  904.  
  905.     // mark the word at the cursor using getword
  906.     function  markword (charset)
  907.       getword charset '' 1
  908.     end
  909.  
  910.     // mark to end-of-line
  911.     function  markeol
  912.       undobegin
  913.       destroymark
  914.       if getcol <= getlinelen then
  915.         markchar (getcol) (getlinelen)
  916.       end
  917.       undoend
  918.     end
  919.  
  920.     // delete a block
  921.     function  deleteblock2
  922.       if getmarkbuf == getcurrbuf then
  923.         deleteblock
  924.       else
  925.         if wintype? "edit" then
  926.           if _DelLine == 'y' then
  927.             delline
  928.           end
  929.         end
  930.       end
  931.     end
  932.  
  933.     // prompt to enter character literally
  934.     function  literal
  935.       say "Enter Literal..."
  936.       queue <char> (char getkey & 0ffh)
  937.     end
  938.  
  939.     // ascii chart with character entry
  940.     function  asciilist
  941.       buffer = asciibuf
  942.       // name it so the position can be remembered
  943.       setbufname "_asc"
  944.       character = (popup buffer '' 13) [10]
  945.       destroybuf
  946.       if character then
  947.         queue <char> character
  948.       end
  949.     end
  950.  
  951.     // support for file name completion (open prompts only)
  952.     function  askcomplete
  953.       if gethistname == "_load" then
  954.         filespec = gettext
  955.         if filespec then
  956.           if not pos "*.*" filespec then
  957.             filespec = filespec + (if? (pos '.' filespec) '*' "*.*")
  958.           end
  959.         else
  960.           filespec = "*.*"
  961.         end
  962.         file = picklist (qualify filespec (getbufname (getwinbuf (getprevwin))))
  963.         if file then
  964.           col 1
  965.           delchar (getlinelen)
  966.           writetext file
  967.           return file
  968.         end
  969.       end
  970.     end
  971.  
  972.     // get the first line of text in the default mark
  973.     function  getmarktext
  974.       if mark? then
  975.         buffer = getmarkbuf
  976.         topline = getmarktop
  977.         if getmarktype == 'l' then
  978.           gettext (getlinebeg topline buffer) (getlinelen topline buffer)
  979.                   (getmarktop) buffer
  980.         else
  981.           gettext (getmarkleft) (getmarkcols) topline buffer
  982.         end
  983.       end
  984.     end
  985.  
  986.     // copy or copy-append to the clipboard
  987.     function  copy (options)
  988.  
  989.       if mark? then
  990.         currentbuf = getcurrbuf
  991.  
  992.         clip = _ClipName
  993.         destroymark clip
  994.         copymark (getmarkuse) clip
  995.  
  996.         // copy
  997.         if options and (buffer? clip) then
  998.           if getmarktype <> 'l' then
  999.             insline '' '' (getlines clip) clip
  1000.           end
  1001.           copyblock clip clip 1 (getlines clip)
  1002.           markline 1 (getlines clip) clip clip
  1003.  
  1004.         // copy append
  1005.         else
  1006.           destroybuf clip
  1007.           createbuf clip
  1008.           copyblock clip clip
  1009.           if getmarktype == 'l' then
  1010.             delline 1 1 clip
  1011.           end
  1012.         end
  1013.         currbuf currentbuf
  1014.       end
  1015.     end
  1016.  
  1017.     // cut or cut-append to the clipboard
  1018.     function  cut (options)
  1019.       if mark? then
  1020.         copy options
  1021.         deleteblock
  1022.       end
  1023.     end
  1024.  
  1025.     // enter a character or string into the current prompt
  1026.     function  write (charstring)
  1027.       writetext charstring
  1028.     end
  1029.  
  1030.  
  1031. // ───────────────────────────────────────────────────────────────────
  1032. //  Edit windows
  1033. // ───────────────────────────────────────────────────────────────────
  1034.  
  1035.   object  edit
  1036.  
  1037.     // mark a paragraph
  1038.     function  markpara
  1039.  
  1040.       if getlinelen then
  1041.  
  1042.         undobegin
  1043.         destroymark
  1044.  
  1045.         // find the beginning of the paragraph
  1046.         pushcursor
  1047.         while up and getlinelen end
  1048.         if not getlinelen then
  1049.           down
  1050.         end
  1051.         markline
  1052.         popcursor
  1053.  
  1054.         // find the end of the paragraph
  1055.         pushcursor
  1056.         while down and getlinelen end
  1057.         if not getlinelen then
  1058.           up
  1059.         end
  1060.         markline
  1061.         popcursor
  1062.  
  1063.         undoend
  1064.  
  1065.         return 1
  1066.       end
  1067.     end
  1068.  
  1069.     // setup for insert-above (copy, move, paste - lineblocks only)
  1070.     function  begabove
  1071.       _ba = ''
  1072.       undobegin
  1073.       if _InsAbove == 'y' and getmarktype == 'l' then
  1074.         _ba = 1
  1075.         if not up then
  1076.           insabove
  1077.           up
  1078.           _ba = 2
  1079.         end
  1080.       end
  1081.     end
  1082.  
  1083.     // end insert-above
  1084.     function  endabove
  1085.       case _ba
  1086.         when 1 down
  1087.         when 2 delline
  1088.       end
  1089.       undoend
  1090.     end
  1091.  
  1092.     // paste or paste-over from the clipboard
  1093.     function  paste (options)
  1094.       if mark? _ClipName then
  1095.         destroymark
  1096.         copymark _ClipName (getmarkuse)
  1097.         if options then
  1098.           copyblockover
  1099.         else
  1100.           begabove
  1101.           copyblock
  1102.           endabove
  1103.         end
  1104.       else
  1105.         say "Nothing to paste" 'b'
  1106.       end
  1107.     end
  1108.  
  1109.     // clear the clipboard
  1110.     function  clear
  1111.       destroybuf _ClipName
  1112.     end
  1113.  
  1114.     // copy a block
  1115.     function  copyblock2
  1116.       if mark? then
  1117.         begabove
  1118.         if not copyblock then
  1119.           say "Copy failed" 'b'
  1120.         end
  1121.         endabove
  1122.       else
  1123.         if _CopyLine == 'y' then
  1124.           undobegin
  1125.           markline
  1126.           copyblock
  1127.           destroymark
  1128.           undoend
  1129.         end
  1130.       end
  1131.     end
  1132.  
  1133.     // move a block
  1134.     function  moveblock2
  1135.       begabove
  1136.       if getmarktop < getviewtop then
  1137.         y = 1 + getrow - (apparentrow  getviewtop - getrow)
  1138.       end
  1139.       if moveblock then
  1140.         if y then
  1141.           adjustrow y
  1142.         end
  1143.       else
  1144.         say "Move failed" 'b'
  1145.       end
  1146.       endabove
  1147.     end
  1148.  
  1149.     // move a block over text
  1150.     function  moveblockover
  1151.       if mark? then
  1152.         undobegin
  1153.         copy
  1154.         fillblock ' '
  1155.         paste 'o'
  1156.         undoend
  1157.       end
  1158.     end
  1159.  
  1160.     // reformat a block or the current paragraph
  1161.     function  formatblock2 (options)
  1162.       undobegin
  1163.       if not mark? then
  1164.         if markpara "tb" then
  1165.           markcolumn (getcol) _RMargin (getmarktop) (getmarkbot)
  1166.           flag = ON
  1167.         end
  1168.       end
  1169.       // special case for single lines
  1170.       if getmarkrows == 1 and getcol < getlinebeg then
  1171.         delchar getlinebeg - getcol
  1172.       else
  1173.         formatblock _LMargin _RMargin options
  1174.       end
  1175.       if flag then
  1176.         destroymark
  1177.       end
  1178.       undoend
  1179.     end
  1180.  
  1181.     // simple quoting support for a block or paragraph
  1182.     function  quote
  1183.       undobegin
  1184.       if not mark? then
  1185.         tempmark = TRUE
  1186.         markpara
  1187.       end
  1188.       if mark? then
  1189.         shiftblock 1 '' '>'
  1190.         if tempmark then
  1191.           destroymark
  1192.         end
  1193.       else
  1194.         say "Nothing to quote"
  1195.       end
  1196.       undoend
  1197.     end
  1198.  
  1199.     // sort a block
  1200.     function  sortblock2
  1201.       sortblock
  1202.         // scrollock ON=descending    // insert ON=ignore case
  1203.         (if? (shiftkey? 10h) 'd')  +  (if? (insert?) 'i')
  1204.  
  1205.     end
  1206.  
  1207.     // prompt to fill a block with a string
  1208.     function  fillblock2
  1209.       askx "Enter fill string" '' "fillblock"
  1210.     end
  1211.  
  1212.     // prompt to save a block
  1213.     function  saveblock2 (options)
  1214.       var c1
  1215.       var c2
  1216.       if mark? then
  1217.         file = ask "Save block as" "_load"
  1218.         if file then
  1219.           file = qualify file (getbufname)
  1220.           addhistory "_load" file
  1221.           if fileattr? file 'r' then
  1222.             say "Read Only!" 'b'
  1223.           else
  1224.             action = locase (askrac file)
  1225.             if pos action "ra" then
  1226.               send "oncomment" file ref c1 ref c2
  1227.               options = _SaveOpt + options
  1228.               if not saveblock file
  1229.                  (if? (pos 'e' options) 'e' + _TabWidth) + options +
  1230.                  (if? action == 'a' 'a')  ''
  1231.                  '' '' (if? c1 c1 + _FoldSign) c2 then
  1232.                 msgbox "Save Failed!" "Error!" 'b'
  1233.               end
  1234.             end
  1235.           end
  1236.         end
  1237.       else
  1238.         say "No marked block" 'b'
  1239.       end
  1240.     end
  1241.  
  1242.     // left justify, center, or right justify a block
  1243.     function  justblock2 (options)
  1244.       justblock options '' _LMargin _RMargin
  1245.     end
  1246.  
  1247.     // destroy open and closed folds
  1248.     function  destroyfold2
  1249.       undobegin
  1250.       if not fold? then
  1251.         closefold
  1252.       end
  1253.       destroyfold
  1254.       undoend
  1255.     end
  1256.  
  1257.     // do fold operations on entire file
  1258.     function  foldall (options)
  1259.       undobegin
  1260.       usemark 'T'
  1261.       markline 1 (getlines)
  1262.       foldblock options
  1263.       destroymark
  1264.       usemark
  1265.       undoend
  1266.     end
  1267.  
  1268.     // fold a block or the current paragraph
  1269.     function  foldblock2
  1270.       undobegin
  1271.       if mark? then
  1272.         foldblock
  1273.       elseif markpara then
  1274.         foldblock
  1275.         destroymark
  1276.       end
  1277.       undoend
  1278.     end
  1279.  
  1280.     // fold a block and destroy subfolds
  1281.     function  foldflat
  1282.       undobegin
  1283.       foldblock 'ds'
  1284.       foldblock
  1285.       undoend
  1286.     end
  1287.  
  1288.     // fold or unfold a line
  1289.     function  foldline (options)
  1290.       undobegin
  1291.       usemark 'T'
  1292.       markline
  1293.       unfold = pos 'u' options
  1294.       if fold? then
  1295.         foldblock 'd'
  1296.         if not unfold or getmarkrows > 1 then
  1297.           bottom = actualrow (if? unfold -1 1) (getmarkbot)
  1298.           if not (getfold 'o' bottom) then
  1299.             markline (getrow) bottom
  1300.           end
  1301.           foldblock
  1302.         end
  1303.       else
  1304.         if not unfold then
  1305.           foldblock
  1306.         end
  1307.       end
  1308.       destroymark
  1309.       usemark
  1310.       undoend
  1311.     end
  1312.  
  1313.     // detab or entab the current file
  1314.     // (+width=detab, -width=entab)
  1315.     function  tabfile (width)
  1316.       undobegin
  1317.       usemark 'T'
  1318.       markline 1 (getlines)
  1319.       tabblock (if? width width _TabWidth)
  1320.       destroymark
  1321.       usemark
  1322.       undoend
  1323.     end
  1324.  
  1325.     // insert a line after the current line with autoindent
  1326.     function  insline2
  1327.       undobegin
  1328.       insline
  1329.       if setting? 'A' then
  1330.         if getlinelen then
  1331.           col (getlinebeg)
  1332.         else
  1333.           nextline = getrow + 2
  1334.           if getlinelen nextline then
  1335.             col (getlinebeg nextline)
  1336.           end
  1337.         end
  1338.       end
  1339.       down
  1340.       undoend
  1341.     end
  1342.  
  1343.     // swap the current line with the next line
  1344.     function  swapline
  1345.       undobegin
  1346.       usemark 'T'
  1347.       markline
  1348.       stopmark
  1349.       down
  1350.       moveblock
  1351.       destroymark
  1352.       usemark
  1353.       undoend
  1354.     end
  1355.  
  1356.     // center the current line
  1357.     function  centerline
  1358.       undobegin
  1359.       usemark 'T'
  1360.       markline
  1361.       justblock 'c' '' _LMargin _RMargin
  1362.       destroymark
  1363.       usemark
  1364.       undoend
  1365.     end
  1366.  
  1367.     // comment or uncomment a line
  1368.     function  commentline (c1 c2)
  1369.       if not c1 then
  1370.         send "oncomment" (getbufname) ref c1 ref c2
  1371.         if not c1 then
  1372.           c1 = '>'
  1373.         end
  1374.       end
  1375.       undobegin
  1376.       column = getlinebeg
  1377.       if (gettext column (sizeof c1)) == c1 then
  1378.         delchar (sizeof c2) getlinelen - (sizeof c2) + 1
  1379.         delchar (sizeof c1) column
  1380.       elseif getlinelen then
  1381.         instext c1 (getlinebeg)
  1382.         if column then
  1383.           ovltext c2  getlinelen + 1
  1384.         end
  1385.       end
  1386.       down
  1387.       undoend
  1388.     end
  1389.  
  1390.     // find the previous word
  1391.     function  prevword
  1392.       while getcol > 1 and (poschar _CSet (getchar)) do
  1393.         left
  1394.       end
  1395.       find _CSet "[r"
  1396.       while getcol > 1 and (poschar _CSet (getchar getcol - 1)) do
  1397.         left
  1398.       end
  1399.     end
  1400.  
  1401.     // find the next word
  1402.     function  nextword
  1403.       while poschar _CSet (getchar) do
  1404.         right
  1405.       end
  1406.       find _CSet '['
  1407.     end
  1408.  
  1409.     // change the case of the word at the cursor
  1410.     function  caseword (options charset)
  1411.       undobegin
  1412.       usemark 'T'
  1413.       markword charset
  1414.       caseblock options
  1415.       destroymark
  1416.       usemark
  1417.       undoend
  1418.     end
  1419.  
  1420.     // open the filename at the cursor
  1421.     function  openword (charset)
  1422.       file = getword (if? charset charset _CSetB)
  1423.       if file then
  1424.         open file
  1425.       end
  1426.     end
  1427.  
  1428.     // delete the character at the cursor
  1429.     function  delchar2
  1430.       undobegin
  1431.       if getcol > getlinelen and _DelJoin == 'y' then
  1432.         joinline
  1433.       else
  1434.         delchar
  1435.         if setting? 'L' then
  1436.           livewrap
  1437.         end
  1438.       end
  1439.       undoend
  1440.     end
  1441.  
  1442.     // backspace
  1443.     function  backsp
  1444.       undobegin
  1445.       if getcol > 1 then
  1446.         left
  1447.         if not insert? and _BakOvl == 'y' then
  1448.           ovltext ' '
  1449.         else
  1450.           delchar
  1451.           if setting? 'L' then
  1452.             livewrap
  1453.           end
  1454.         end
  1455.       elseif getrow > 1 and _BakJoin == 'y' then
  1456.         up
  1457.         col getlinelen + 1
  1458.         joinline
  1459.       end
  1460.       undoend
  1461.     end
  1462.  
  1463.     // delete right word
  1464.     function  delword (charset)
  1465.       if not charset then
  1466.         charset = _CSet
  1467.       end
  1468.       undobegin
  1469.       if getcol > getlinelen then
  1470.         joinline
  1471.       else
  1472.         p = posnot charset (gettext (getcol))
  1473.         if p > 1 then
  1474.           delchar p - 1
  1475.         end
  1476.         delchar (
  1477.           if p then
  1478.             if getchar == ' ' and
  1479.                  (getcol == 1 or
  1480.                  (posnot charset (getchar getcol - 1))) then
  1481.               (posnot ' ' (gettext (getcol))) - 1
  1482.             else
  1483.               p == 1
  1484.             end
  1485.           else
  1486.             getlinelen
  1487.           end
  1488.         )
  1489.       end
  1490.       if setting? 'L' then
  1491.         livewrap
  1492.       end
  1493.       undoend
  1494.     end
  1495.  
  1496.     // splitline with autoindent
  1497.     function splitline2 (column)
  1498.       undobegin
  1499.       b = getlinebeg
  1500.       if splitline column then
  1501.         if not setting? 'A' then
  1502.           b = _LMargin
  1503.         end
  1504.         if b > 1 then
  1505.           pushcursor
  1506.           down
  1507.           usemark 'T'
  1508.           markline
  1509.           shiftblock (if? getcol > b  b  (getcol)) - 1
  1510.           destroymark
  1511.           usemark
  1512.           popcursor
  1513.         end
  1514.       end
  1515.       undoend
  1516.     end
  1517.  
  1518.     // <enter> key behavior
  1519.     function  enter
  1520.  
  1521.       // terminate a word for text translation
  1522.       lastrow = getrow
  1523.       if getcol == getlinelen + 1 and getlinelen then
  1524.         if setting? 'T' then
  1525.           send <char> ' '
  1526.         end
  1527.       end
  1528.  
  1529.       if getrow == lastrow then
  1530.         case (if? (insert?) _EnterIns _EnterOvl)
  1531.           when 'i'
  1532.             insline2
  1533.           when 's'
  1534.             if fold? then
  1535.               insline2
  1536.             else
  1537.               startcolumn = getlinebeg
  1538.               length = getlinelen
  1539.               splitline2
  1540.               down
  1541.               if setting? 'A' then
  1542.                 if length then
  1543.                   col startcolumn
  1544.                 end
  1545.               else
  1546.                 startcolumn = _LMargin
  1547.                 col (if? startcolumn startcolumn 1)
  1548.               end
  1549.             end
  1550.           otherwise
  1551.             down
  1552.             col (if? (getlinelen) (getlinebeg) _LMargin)
  1553.         end
  1554.       end
  1555.     end
  1556.  
  1557.     // for use by variable tab right
  1558.     function  vtabr
  1559.       i = 1
  1560.       while i <= arg do
  1561.         if (arg i) <= getcol then
  1562.           i = i + 1
  1563.         else
  1564.           return arg i
  1565.         end
  1566.       end
  1567.       return 0
  1568.     end
  1569.  
  1570.     // for use by variable tab left
  1571.     function  vtabl
  1572.       i = arg
  1573.       while i do
  1574.         if (arg i) >= getcol then
  1575.           i = i - 1
  1576.         else
  1577.           return arg i
  1578.         end
  1579.       end
  1580.       return 0
  1581.     end
  1582.  
  1583.     // tab support
  1584.     function  tabfunc (next)
  1585.  
  1586.       oldcolumn = getcol
  1587.  
  1588.       // smart tabs
  1589.       if setting? 'S' then
  1590.         prevline = getrow - 1
  1591.         while prevline and not (getlinelen prevline) do
  1592.           prevline = prevline - 1
  1593.         end
  1594.         if prevline then
  1595.           pushcursor
  1596.           row prevline
  1597.           send (if? next "nextword" "prevword")
  1598.           if prevline == getrow then
  1599.             newcolumn = getcol
  1600.           end
  1601.           popcursor
  1602.         end
  1603.       end
  1604.  
  1605.       // variable tabs
  1606.       if not newcolumn then
  1607.         if setting? 'V' then
  1608.           newcolumn = eval (if? next "vtabr " "vtabl ") + _VarTabs
  1609.         end
  1610.  
  1611.         // standard interval tabs
  1612.         if not newcolumn then
  1613.           width = _TabWidth
  1614.           if not width then
  1615.             width = 8
  1616.           end
  1617.           newcolumn = oldcolumn +
  1618.                         if next then
  1619.                           width - (oldcolumn - 1) mod width
  1620.                         elseif oldcolumn > 1 then
  1621.                           -((oldcolumn - 2) mod width + 1)
  1622.                         end
  1623.         end
  1624.       end
  1625.  
  1626.       // move to tabstop and shift text if needed
  1627.       if newcolumn then
  1628.         if _TabShift == 'y' and insert? then
  1629.           if newcolumn < oldcolumn then
  1630.             delchar  oldcolumn - newcolumn  newcolumn
  1631.           elseif newcolumn > oldcolumn then
  1632.             instext (copystr ' ' newcolumn - oldcolumn)
  1633.           end
  1634.         end
  1635.         col newcolumn
  1636.       end
  1637.     end
  1638.  
  1639.     // tab left and right
  1640.     function  tabright    tabfunc 1  end
  1641.     function  tableft     tabfunc    end
  1642.  
  1643.     // prompt to verify close
  1644.     function  close?
  1645.       if bufchanged? and not getprevcurs then
  1646.         savechanges = popup "ync"  "Save changes to " +
  1647.                                         (getname (getbufname)) + '?'
  1648.         if savechanges == "Yes" then
  1649.           save
  1650.         end
  1651.         icompare savechanges "Yes" "No"
  1652.       else
  1653.         1
  1654.       end
  1655.     end
  1656.  
  1657.     // close an edit window
  1658.     function  close (options)
  1659.       if pos 's' options then
  1660.         if save then
  1661.           pass
  1662.         end
  1663.       elseif close? then
  1664.         pass
  1665.       end
  1666.     end
  1667.  
  1668.     // open and insert prompt
  1669.     function  askinsert
  1670.       file = ask  "File to insert into " + (getname (getbufname)) "_load"
  1671.       if file then
  1672.         // addhistory not needed for open
  1673.         old_size = getlines
  1674.         undobegin
  1675.         open file 'i'
  1676.         // mark the inserted text
  1677.         if getlines > old_size then
  1678.           markline  getrow + 1  getrow + getlines - old_size
  1679.         end
  1680.         undoend
  1681.       end
  1682.     end
  1683.  
  1684.     // prompt to change the current file name
  1685.     function  askname
  1686.       newname = ask  "Rename " + (getname (getbufname)) + " to"  "_load"
  1687.       if newname then
  1688.         case setname newname
  1689.           when -1 say "Failed" 'b'
  1690.           when -2 say "Failed - file already loaded" 'b'
  1691.           otherwise
  1692.             addhistory "_load" (getbufname)
  1693.         end
  1694.       end
  1695.     end
  1696.  
  1697.     // search and replace with messages and highlighting
  1698.     function  search2 (search_str reverse again)
  1699.       var opt
  1700.       var rpl
  1701.       n = search search_str reverse again ref opt ref rpl
  1702.       if n then
  1703.         // replace occurred
  1704.         if rpl then
  1705.           display
  1706.           say (thousands n) + " changes made"
  1707.         // count occurrences
  1708.         elseif pos 'a' opt then
  1709.           display
  1710.           say (thousands n) + " occurrences of '" + search_str + "' found"
  1711.         // search only
  1712.         else
  1713.           onfound n
  1714.         end
  1715.       else
  1716.         display
  1717.         say "'" + search_str + "' not found"  'b'
  1718.       end
  1719.       return n
  1720.     end
  1721.  
  1722.     // find prompt
  1723.     function  askfind (reverse)
  1724.       search_string = if _PromptStyle == 'd' then
  1725.                         finddlg
  1726.                       else
  1727.                         ask "[string/abgirswx] Find"  "_find"
  1728.                       end
  1729.       if search_string then
  1730.         search2 search_string reverse
  1731.         addhistory "_find" search_string
  1732.       end
  1733.     end
  1734.  
  1735.     // replace prompt
  1736.     function  askrepl (reverse)
  1737.       search_string = if _PromptStyle == 'd' then
  1738.                         repldlg
  1739.                       else
  1740.                         ask "[string/replstr/abgirswx] Repl"  "_find"
  1741.                       end
  1742.       if search_string then
  1743.         search2 search_string reverse
  1744.         addhistory "_find" search_string
  1745.       end
  1746.     end
  1747.  
  1748.     // do the last find/replace operation
  1749.     // (reverse=r reverses the search direction)
  1750.     function  findlast (reverse)
  1751.       search2 (gethiststr "_find") reverse TRUE
  1752.     end
  1753.  
  1754.     // incremental search
  1755.     function  isearch
  1756.  
  1757.       var search_string
  1758.  
  1759.       repeat
  1760.  
  1761.         settitle  "I-search for [" + search_string + "] "
  1762.         keycode = getkey
  1763.         options = _SearchOpt
  1764.         new_char = ''
  1765.  
  1766.         case  keycode
  1767.  
  1768.           when <backspace>
  1769.             if search_string then
  1770.               popcursor
  1771.               search_string = if (sizeof search_string) > 1 then
  1772.                                 search_string [1 : (sizeof search_string) - 1]
  1773.                               else
  1774.                                 ''
  1775.                               end
  1776.               if not search_string then
  1777.                 display
  1778.               end
  1779.               options = '*'
  1780.             end
  1781.  
  1782.           when <ctrl p>, <ctrl r>
  1783.             options = 'r'
  1784.  
  1785.           when <ctrl n>, <ctrl l>
  1786.             // do nothing
  1787.  
  1788.           when <ctrl g>, <ctrl b>
  1789.             options = 'g'
  1790.  
  1791.           otherwise
  1792.             keyname = getkeyname keycode
  1793.             if (sizeof keyname) == 3 then
  1794.               pushcursor
  1795.               new_char = keyname [2]
  1796.               options = '*'
  1797.             else
  1798.  
  1799.               // restore window title
  1800.               settitle (getbufname)
  1801.               display
  1802.  
  1803.               // clear all pushed cursors
  1804.               popcursor "ad"
  1805.               addhistory "_find" search_string
  1806.  
  1807.               if keycode <> <enter> and keycode <> <esc> then
  1808.                 queuekey keycode
  1809.               end
  1810.  
  1811.               done = TRUE
  1812.             end
  1813.         end
  1814.  
  1815.         if not done and (search_string or new_char) then
  1816.           str_length = find search_string + new_char  _SearchOpt + options
  1817.           if str_length then
  1818.             onfound str_length
  1819.             search_string = search_string + new_char
  1820.           else
  1821.             say  search_string + new_char + " not found"  'b'
  1822.             if new_char then
  1823.               popcursor
  1824.             end
  1825.             onfound (sizeof search_string)
  1826.           end
  1827.         end
  1828.  
  1829.       until done
  1830.     end
  1831.  
  1832.  
  1833.     // find occurrences search
  1834.     function  findo (string_and_opt)
  1835.  
  1836.       var search_string
  1837.       var options
  1838.       var o
  1839.  
  1840.       n = splitstr '' string_and_opt
  1841.                    ref search_string  ref options  ref o
  1842.  
  1843.       // initialize search options
  1844.       if n >= 2 then
  1845.         if n > 2 then
  1846.           options = o
  1847.         end
  1848.         if pos 'g' options then
  1849.           options = sub 'g' '' options
  1850.         end
  1851.       else
  1852.         options = _SearchOpt
  1853.       end
  1854.       options = options + '*'
  1855.  
  1856.       // do the search
  1857.       buffer = createbuf
  1858.       ovltext "≡≡≡≡≡≡ Select this line to edit occurrences ≡≡≡≡≡≡"
  1859.       gotobuf (getprevbuf)
  1860.       pushcursor
  1861.       gotopos 1 1
  1862.       while find  search_string options  do
  1863.         addline  getrow + ": " + gettext  '' '' buffer
  1864.         col MAX_COL
  1865.       end
  1866.       popcursor
  1867.  
  1868.       // display occurrences
  1869.       if (getlines buffer) > 1 then
  1870.         bname = getbufname
  1871.         line = popup buffer
  1872.                  "Occurrences of '" + search_string + "' in "
  1873.                  + (getname bname) + " - " + ((getlines buffer) - 1) +
  1874.                  " lines"   getvidcols - 11 getvidrows - 8
  1875.         if line then
  1876.           if line [1] == '≡' then
  1877.             delline 1 1 buffer
  1878.             setbufname (qualify "TEMP.TXT" bname) buffer
  1879.             openbuf buffer
  1880.           else
  1881.             destroybuf buffer
  1882.             gotopos 1 line [1 : (pos ':' line) - 1]
  1883.             onfound (find search_string  options + '*')
  1884.           end
  1885.         end
  1886.       else
  1887.         destroybuf buffer
  1888.         display
  1889.         say  "'" + string_and_opt + "' not found"  'b'
  1890.       end
  1891.     end
  1892.  
  1893.     // prompt to find occurrences
  1894.     function  askfindo
  1895.       search_str = ask "[string/birswx] Find occurrences of"  "_find"
  1896.       if search_str then
  1897.         findo search_str
  1898.         addhistory "_find" search_str
  1899.       end
  1900.     end
  1901.  
  1902.     // find all occurrences of last find string
  1903.     function  findlasto
  1904.       findo (gethiststr "_find")
  1905.     end
  1906.  
  1907.     // find matching character (){}[]<>
  1908.     function  gotomatch2
  1909.       if gotomatch "(){}[]<>" then
  1910.         onfound 1
  1911.       else
  1912.         say "Not found" 'b'
  1913.       end
  1914.     end
  1915.  
  1916.     // goto column
  1917.     function  col2 (column)
  1918.       case column [1]
  1919.         when '+'   right  column [2 : TO_END]
  1920.         when '-'   left   column [2 : TO_END]
  1921.         otherwise  col (if? column > MAX_COL MAX_COL column)
  1922.       end
  1923.       onfound
  1924.     end
  1925.  
  1926.     // goto line
  1927.     function  row2 (line)
  1928.       case line [1]
  1929.         when '+'   down line [2 : TO_END]
  1930.         when '-'   up   line [2 : TO_END]
  1931.         otherwise  row (if? line > getlines (getlines) line)
  1932.       end
  1933.       onfound
  1934.     end
  1935.  
  1936.     // goto line prompt
  1937.     function  askrow
  1938.       askx "Line number" "_line" "row2"
  1939.     end
  1940.  
  1941.     // goto column prompt
  1942.     function  askcol
  1943.       askx "Column Number" '' "col2"
  1944.     end
  1945.  
  1946.     // set a quick bookmark
  1947.     function  quickbook
  1948.       _bk = _bk + 1
  1949.       bookmark = "Book" + _bk
  1950.       setbook bookmark
  1951.       display
  1952.       say "Bookmark " + bookmark + " set"
  1953.     end
  1954.  
  1955.     // place a bookmark
  1956.     function  placebook (bookmark)
  1957.       if not bookmark then
  1958.         bookmark = ask "Bookmark Name" "_book"
  1959.       end
  1960.       if bookmark then
  1961.         setbook bookmark
  1962.         display
  1963.         say "Bookmark '" + bookmark + "' set"
  1964.       end
  1965.     end
  1966.  
  1967.  
  1968.     // Go to the compiler error on the current line of a compiler
  1969.     // error output file. This function recognizes compiler errors
  1970.     // of the form:
  1971.     //
  1972.     //   <text>  FILENAME.EXT  <text>  LINENUMBER  <text> : MESSAGE
  1973.     //
  1974.     // (implemented by using regular expression searching confined
  1975.     // to the current line)
  1976.  
  1977.     function  gotoerror
  1978.       pushcursor
  1979.       // filename charclass to use (max closure without the period)
  1980.       fileset = "[a-zA-Z0-9_\-/\\\\@~:^!#$%&`']#"
  1981.       file_ext =  fileset + '\\.' + fileset
  1982.       // find the filename
  1983.       length = find file_ext 'xgl*'
  1984.       if length then
  1985.         filename = gettext (getcol) length
  1986.         right length
  1987.         // find the line number
  1988.         length = find "[0-9]#" 'xl'
  1989.         if length then
  1990.           line = gettext (getcol) length
  1991.           // find the message
  1992.           if find ':' 'l' then
  1993.             message = gettext getcol + 1
  1994.             popcursor
  1995.             // open the file
  1996.             if open filename then
  1997.               row line
  1998.               col (getlinebeg)
  1999.               send "onfound"
  2000.               say  message + '  '
  2001.               return
  2002.             end
  2003.           end
  2004.         end
  2005.       end
  2006.       popcursor
  2007.       display
  2008.       say "Compiler message not recognized."
  2009.     end
  2010.  
  2011.  
  2012.     // backup a file and return the backup filename if sucessful
  2013.     function  backup (file)
  2014.       if locatefile file then
  2015.         dir = _BackupDir
  2016.         if dir then
  2017.           if (sizeof dir) > 3 and  dir [LAST_CHAR] == "\\" then
  2018.             dir = dir [1 : (sizeof dir) - 1]
  2019.           end
  2020.           createdir dir
  2021.           dir = qualify dir
  2022.           backup_file = if pos "*.*" dir then
  2023.                           qualify (getname file) dir
  2024.                         else
  2025.                           msgbox "Unable to create backup file!"
  2026.                                  "Warning!"
  2027.                           return 1
  2028.                         end
  2029.         else
  2030.           backup_file = forceext file _BackupExt
  2031.         end
  2032.  
  2033.         // delete the old backup file
  2034.         deletefile backup_file
  2035.  
  2036.         // attempt a rename
  2037.         if not renamefile file backup_file then
  2038.           // try copy if rename fails
  2039.           if (copyfile file backup_file) <= 0 then
  2040.             msgbox "File backup failed!" "Error"
  2041.             return 0
  2042.           end
  2043.         end
  2044.         return backup_file
  2045.       else
  2046.         return 1
  2047.       end
  2048.     end
  2049.  
  2050.     // save the current file to disk
  2051.     function  save (file options)
  2052.       var c1
  2053.       var c2
  2054.  
  2055.       // check for a truncated file
  2056.       if trunc? and
  2057.          not (icompare (popup "ok" "Truncated file - are you sure?") "Ok") then
  2058.         return
  2059.       end
  2060.  
  2061.       file = if file then
  2062.                qualify file (getbufname)
  2063.              else
  2064.                getbufname
  2065.              end
  2066.       if fileattr? file 'r' then
  2067.         say "Read Only!" 'b'
  2068.       else
  2069.         backup_file = 1
  2070.         if setting? 'B' then
  2071.           backup_file = backup file
  2072.         end
  2073.         if not backup_file then
  2074.           say "Backup failed" 'b'
  2075.         else
  2076.           send "onsave" file
  2077.  
  2078.           // get fold comments for the file (if any)
  2079.           send "oncomment" file ref c1 ref c2
  2080.           options = _SaveOpt + options
  2081.           if not savebuf file
  2082.                    (if? (pos 'e' options) 'e' + _TabWidth) + options  ''
  2083.                    (if not getbinarylen then hex2bin _LineDlm end) ''
  2084.                    (if? c1 c1 + _FoldSign) c2 then
  2085.  
  2086.             // restore the backup after save failure
  2087.             if backup_file <> 1 then
  2088.               if not renamefile backup_file file then
  2089.                 copyfile backup_file file
  2090.               end
  2091.             end
  2092.             msgbox "Save failed!  Check file path / file attributes / disk space"  "Error!" 'b'
  2093.             return 0
  2094.           else
  2095.             1
  2096.           end
  2097.         end
  2098.       end
  2099.     end
  2100.  
  2101.     // save-as prompt
  2102.     function  asksaveas (options)
  2103.       file = ask "Save " + (getname (getbufname)) + " as"  "_load"
  2104.       if file then
  2105.         file = qualify file (getbufname)
  2106.         addhistory "_load" file
  2107.         save file options
  2108.       end
  2109.     end
  2110.  
  2111.     // start, stop, or do autosave
  2112.     function  autosave (seconds)
  2113.       if not seconds then
  2114.         if bufchanged? then
  2115.           save
  2116.         end
  2117.       elseif seconds < 0 then
  2118.         destroytimer "asav"
  2119.       else
  2120.         setrepeat "asav" seconds * 1000  '' "autosave"
  2121.       end
  2122.     end
  2123.  
  2124.     // prompt for autosave interval in seconds
  2125.     function  askasave
  2126.       seconds = ask "Autosave interval in secs (-1=disable)"
  2127.       if seconds then
  2128.         autosave seconds
  2129.       end
  2130.     end
  2131.  
  2132.     // highlight all occurrences of the word at the cursor
  2133.     function hiliteword
  2134.       sobj = send "onsyntax" (getbufname)
  2135.       if not sobj then
  2136.         setting 'X' DEFAULT
  2137.         sobj = "syndef"
  2138.       end
  2139.       if sobj then
  2140.         w = send "getword" "a-zA-Z_0-9?"
  2141.         if w then
  2142.           // create a color selection menu
  2143.           menu "hcolor"
  2144.             item " &None"           -1
  2145.             item " &Default"        -2
  2146.             item "-"
  2147.             item " &Black"          color white on black
  2148.             item " B&lue"           color yellow on blue
  2149.             item " &Green"          color white on green
  2150.             item " &Cyan"           color white on cyan
  2151.             item " &Red"            color white on red
  2152.             item " &Magenta"        color white on magenta
  2153.             item " Br&own"          color white on brown
  2154.             item " Gr&ay"           color white on gray
  2155.             item "-"
  2156.             item " Dar&kgray"       color white on darkgray
  2157.             item " Brightbl&ue"     color white on brightblue
  2158.             item " Brightgr&een"    color black on brightgreen
  2159.             item " Brig&htcyan"     color black on brightcyan
  2160.             item " Br&ightred"      color white on brightred
  2161.             item " Brightmagen&ta"  color white on brightmagenta
  2162.             item " &Yellow"         color black on yellow
  2163.             item " &White"          color black on white
  2164.           end
  2165.           setbufname "colorlist"
  2166.           hcolor = popup "hcolor" "select a color "
  2167.           // destroy the menu
  2168.           destroybuf "hcolor"
  2169.           if hcolor then
  2170.             if hcolor == -1 then
  2171.               unsetx w sobj
  2172.             else
  2173.               setxobj w (if? hcolor == -2 '' hcolor) sobj
  2174.             end
  2175.           end
  2176.           display
  2177.         end
  2178.       end
  2179.     end
  2180.  
  2181.     // live word wrap support
  2182.     function livewrap
  2183.  
  2184.       if fold? then
  2185.         return
  2186.       end
  2187.  
  2188.       startcol = getlinebeg
  2189.       if getrow < getlines and (getlinelen  getrow + 1) then
  2190.         n = getlinebeg  getrow + 1
  2191.         startcol = if? n < startcol  n  startcol
  2192.       elseif not getlinelen then
  2193.         startcol = _LMargin
  2194.       end
  2195.  
  2196.       if getcol < startcol then
  2197.         startcol = getcol
  2198.       end
  2199.  
  2200.       if getlinelen then
  2201.         undobegin
  2202.         saved_char = getchar
  2203.         ovltext '■'
  2204.  
  2205.         // mark to the end of the paragraph
  2206.         pushcursor
  2207.         top = getrow
  2208.         while down and getlinelen do
  2209.         end
  2210.         if not getlinelen then
  2211.           up
  2212.         end
  2213.         bottom = getrow
  2214.         popcursor
  2215.  
  2216.         // reformat
  2217.         usemark 'T'
  2218.         markcolumn startcol _RMargin top bottom
  2219.         formatblock '' '' "kr"
  2220.         destroymark
  2221.         usemark
  2222.  
  2223.         // find the original cursor position
  2224.         col 1
  2225.         find '■' '*'
  2226.         ovltext (if? saved_char saved_char ' ')
  2227.  
  2228.         undoend
  2229.       end
  2230.     end
  2231.  
  2232.     // enter a character or string at the cursor, with support for:
  2233.     //   - match character
  2234.     //   - translate
  2235.     //   - standard word wrap
  2236.     //   - live word wrap
  2237.  
  2238.     function  write (write_str)
  2239.  
  2240.       // group together as one undoable operation
  2241.       undobegin
  2242.  
  2243.       // enter the character or string at the cursor and
  2244.       // advance the cursor
  2245.       writetext write_str
  2246.  
  2247.       // get the current window settings
  2248.       setting_str = getsettings
  2249.  
  2250.       // match character
  2251.       if pos 'M' setting_str then
  2252.         instext ( case write_str
  2253.                     when '"'  '"'
  2254.                     when '('  ')'
  2255.                     when '['  ']'
  2256.                     when '{'  '}'
  2257.                     otherwise ''
  2258.                   end )
  2259.       end
  2260.  
  2261.       // translate
  2262.       if pos 'T' setting_str then
  2263.  
  2264.         // delimited lookup?
  2265.         to_word_end = if? (posnot _TranCSet write_str) 2 1
  2266.  
  2267.         // get the last word typed
  2268.         word_str = getword _TranCSet (getcol - to_word_end)
  2269.         if word_str then
  2270.           lookup_str = word_str + (if? to_word_end == 2 '*')
  2271.  
  2272.           // lookup the word in the translate object
  2273.           value = lookup lookup_str _TranObj
  2274.  
  2275.           if value then
  2276.             // is it a function? ..then evaluate it
  2277.             if function? lookup_str _TranObj then
  2278.               eval value
  2279.  
  2280.             // otherwise replace the word
  2281.             else
  2282.               word_column = getcol - (sizeof word_str) - to_word_end + 1
  2283.               delchar (sizeof word_str) word_column
  2284.               instext value word_column
  2285.               col word_column + (sizeof value) + to_word_end - 1
  2286.             end
  2287.           end
  2288.         end
  2289.       end
  2290.  
  2291.       // check for word wrap or live wrap
  2292.       if getlinelen > _RMargin then
  2293.  
  2294.         // live word wrap
  2295.         if pos 'L' setting_str then
  2296.           livewrap
  2297.  
  2298.         // standard word wrap
  2299.         elseif (pos 'W' setting_str) and (not fold?) then
  2300.           column = getcol
  2301.           limit = _RMargin + 1
  2302.           if column > limit then
  2303.             if write_str <> ' ' then
  2304.               first_col = if? (setting? 'A') (getlinebeg) _LMargin
  2305.               split_col = pos ' ' (gettext 1 limit) 'r'
  2306.               split_col = if? split_col > first_col  split_col + 1  limit
  2307.               splitline split_col
  2308.               down
  2309.               markline '' '' 'T'
  2310.               shiftblock  first_col - 1 'T'
  2311.               destroymark 'T'
  2312.               col  column - split_col + first_col
  2313.             end
  2314.           end
  2315.         end
  2316.       end
  2317.  
  2318.       undoend
  2319.     end
  2320.  
  2321.     // enter a date/time stamp at the cursor
  2322.     function  timestamp
  2323.       write getdate + ' ' + gettime
  2324.     end
  2325.  
  2326.  
  2327. // ───────────────────────────────────────────────────────────────────
  2328. //  File Manager windows
  2329. // ───────────────────────────────────────────────────────────────────
  2330.  
  2331.   object  fmgr
  2332.  
  2333.     // return the file name for fmgr commands
  2334.     function  fname2
  2335.       if fmark? then
  2336.         "MARKED FILES"
  2337.       else
  2338.         getname (getffile)
  2339.       end
  2340.     end
  2341.  
  2342.     // error notification
  2343.     function  ferror (s)
  2344.       msgbox  s + " Failed"  "Error!" 'b'
  2345.     end
  2346.  
  2347.     // fmgr confirmation prompt
  2348.     function  fconfirm (confirm pstring func)
  2349.       if (icompare confirm 'n') or
  2350.          (icompare (popup "ok" pstring + ' ' + fname2 + '?') "ok") then
  2351.         fdomark func
  2352.         reopen
  2353.       end
  2354.     end
  2355.  
  2356.     // internal fopen
  2357.     function  fopn (file options)
  2358.       if file then
  2359.         openf file options
  2360.       else
  2361.         fdomark "fopn" options
  2362.       end
  2363.     end
  2364.  
  2365.     // fmgr open file(s) command
  2366.     function  fopen (options)
  2367.  
  2368.       var searchopt
  2369.  
  2370.       if pos '1' options then
  2371.         if shiftkey? then
  2372.           options = options + 'v'
  2373.         end
  2374.         scanstr = fscanstr
  2375.         openf '' options
  2376.  
  2377.         // find first occurrence for scan windows
  2378.         if scanstr then
  2379.           addhistory "_find" scanstr
  2380.           splitstr '' scanstr '' ref searchopt
  2381.           gotopos 1 (if? (pos 'r' searchopt) (getlines) 1)
  2382.           send "onfound" (search scanstr)
  2383.         end
  2384.  
  2385.       else
  2386.         fopn '' options
  2387.       end
  2388.     end
  2389.  
  2390.     // fmgr change file attributes command
  2391.     function  fattr (file attr)
  2392.       if file then
  2393.         chgfileattr file attr
  2394.       else
  2395.         attr = ask "New attributes [AHSR] for " + fname2
  2396.         if attr then
  2397.           fdomark "fattr" (if? attr <> ' ' attr)
  2398.           reopen
  2399.         end
  2400.       end
  2401.     end
  2402.  
  2403.     // fmgr delete file(s) command
  2404.     function  fdelete (file)
  2405.       if file then
  2406.         if pos "*.*" file then
  2407.           file = getpath file
  2408.         end
  2409.         if not deletefile file 'd' then
  2410.           ferror "Delete"
  2411.         end
  2412.       else
  2413.         fconfirm _ConDel "Delete" "fdelete"
  2414.       end
  2415.     end
  2416.  
  2417.     // fmgr touch file(s) command
  2418.     function  ftouch (file)
  2419.       if file then
  2420.         if not touchfile file then
  2421.           ferror "Touch"
  2422.         end
  2423.       else
  2424.         fconfirm _ConTch "Touch" "ftouch"
  2425.       end
  2426.     end
  2427.  
  2428.     // print a file or directory with the current printer settings
  2429.     function  printfile (file)
  2430.       if loadbuf file '' '' _FmgrOpt _TruncLength then
  2431.         print
  2432.         destroybuf
  2433.       end
  2434.     end
  2435.  
  2436.     // fmgr print file(s) command
  2437.     function  fprint (file)
  2438.       if file then
  2439.         if not printfile file then
  2440.           ferror "Print"
  2441.         end
  2442.       else
  2443.         fconfirm 'y' "Print" "fprint"
  2444.       end
  2445.     end
  2446.  
  2447.     // fmgr run file command
  2448.     function  frun (options)
  2449.       run (getffile) options
  2450.       reopen
  2451.     end
  2452.  
  2453.     // fmgr rename file command
  2454.     function  frename
  2455.       oldname = getffile
  2456.       newname = ask  "Rename " + (getname oldname) + " to"  "_load"
  2457.       if newname then
  2458.         if renamefile oldname (qualify newname (getbufname)) then
  2459.           reopen
  2460.         else
  2461.           ferror "Rename"
  2462.         end
  2463.       end
  2464.     end
  2465.  
  2466.     // fmgr copy (or move) file(s) command
  2467.     function  fcopy (source dest options)
  2468.       if source then
  2469.         if dir? dest then
  2470.           dest = qualify (getname source) dest
  2471.         end
  2472.         action = askrac dest
  2473.         if pos action "ra" 'i' then
  2474.           move? = options == 'm'
  2475.           say (if? move? "Mov" "Copy") + "ing " + source "..."
  2476.           if not move? or (icompare action 'a') or not (renamefile source dest) then
  2477.             if not copyfile source dest (if? (icompare action 'a') 'a') then
  2478.               ferror (if? move? "Move" "Copy")
  2479.               fdobrk
  2480.             else
  2481.               if move? then
  2482.                 deletefile source
  2483.               end
  2484.             end
  2485.           end
  2486.         end
  2487.       else
  2488.         if fmark? then
  2489.           dir_dest = qualify (getffile)
  2490.           if not dir? dir_dest then
  2491.             dir_dest = ''
  2492.           end
  2493.         end
  2494.         dest = ask (if? options == 'm' "Move " "Copy ") + fname2 + " to"
  2495.                    "_load" dir_dest
  2496.         if dest then
  2497.           fdomark "fcopy" (qualify dest (getbufname)) options
  2498.           reopen
  2499.         end
  2500.       end
  2501.     end
  2502.  
  2503.     // fmgr move file(s) command
  2504.     function  fmove
  2505.       fcopy '' '' 'm'
  2506.     end
  2507.  
  2508.     // fmgr create new directory command
  2509.     function  fmkdir
  2510.       dir = ask "New directory name" "_load"
  2511.       if dir then
  2512.         if createdir (qualify dir (getbufname)) then
  2513.           reopen
  2514.         else
  2515.           ferror "Create directory"
  2516.         end
  2517.       end
  2518.     end
  2519.  
  2520.  
  2521. // ───────────────────────────────────────────────────────────────────
  2522. //  On-Event functions called by the editor
  2523. // ───────────────────────────────────────────────────────────────────
  2524.  
  2525.   // edit windows & file manager windows only
  2526.   object  edit_fmgr
  2527.  
  2528.     // called while loading files
  2529.     function  onloading (lines)
  2530.       say (if? lines  "Loading [" + lines + "]..."  getbufname)
  2531.     end
  2532.  
  2533.     // called while saving files
  2534.     function  onsaving (lines)
  2535.       say (if? lines  "Saving [" + lines + "]..."  getbufname)
  2536.     end
  2537.  
  2538.     // called while printing files
  2539.     function  onprinting (lines)
  2540.       say (if? lines  "Printing [" + lines + "]... <ctrl break> to stop "
  2541.            getbufname)
  2542.     end
  2543.  
  2544.     // called while scanning files
  2545.     function  onscanning (file found)
  2546.  
  2547.       // create scan progress window
  2548.       if not window? 'scan' then
  2549.  
  2550.         createwindow 'scan'
  2551.         setwinobj
  2552.         setframe ">b"
  2553.         setcolor  border_color   color white on gray
  2554.         setcolor  text_color     color black on gray
  2555.         settitle "Scanning" 'c'
  2556.         setborder "1i"
  2557.         setshadow 2 1
  2558.  
  2559.         // center the window
  2560.         width = (sizeof (getpath file)) + 24
  2561.         height = 16
  2562.         ox = (getvidcols - width) / 2
  2563.         oy = (getvidrows - height) / 2
  2564.         sizewindow ox oy ox + width oy + height "ad"
  2565.         writestr   file + "..."
  2566.  
  2567.       elseif found then
  2568.         writestr " FOUND" (color brightgreen on gray) (getcoord 'x1') - 7
  2569.  
  2570.       elseif file then
  2571.         writeline
  2572.         writestr   file + "..."
  2573.  
  2574.       else
  2575.         destroywindow
  2576.       end
  2577.  
  2578.       display
  2579.     end
  2580.  
  2581.     // called while compiling files
  2582.     function  oncompiling (file lines)
  2583.       say (if? lines  "Compiling " + file + " [" + lines + "]..."  getbufname)
  2584.     end
  2585.  
  2586.  
  2587.   // edit windows only
  2588.   object  edit
  2589.  
  2590.     // called after a file is opened and before it's displayed
  2591.     function  onopen
  2592.  
  2593.       // set window event object
  2594.       setwinobj "edit"
  2595.  
  2596.       // default window settings (if not remembered by open)
  2597.       if not getsettings then
  2598.         setting _DefaultSet ON
  2599.       end
  2600.  
  2601.       // check for file truncation
  2602.       if trunc? then
  2603.         display
  2604.         say "File Truncated!" 'b'
  2605.       end
  2606.     end
  2607.  
  2608.     // called immediately before a file is saved
  2609.     //function  onsave (file) then
  2610.     //end
  2611.  
  2612.     // called when switching to a file
  2613.     //function  onfocus
  2614.     //end
  2615.  
  2616.     // called when closing a file
  2617.     //function  onclose
  2618.     //end
  2619.  
  2620.     // called after a search to change the window view and
  2621.     // optionally highlight a string
  2622.     function  onfound (stringlength)
  2623.  
  2624.       // check if the cursor is outside the window view
  2625.       if getcol < getviewleft then
  2626.         if getcol < getviewcols then
  2627.           rollcol -getviewleft
  2628.         else
  2629.           adjustcol 3
  2630.         end
  2631.       elseif getcol + stringlength >= getviewright then
  2632.         adjustcol
  2633.       end
  2634.  
  2635.       if getrow > getviewbot then
  2636.         adjustrow 3
  2637.       elseif getrow < getviewtop then
  2638.         adjustrow
  2639.       end
  2640.       display
  2641.  
  2642.       // highlight a string if stringlength is specified
  2643.       if stringlength then
  2644.         hilite stringlength 1 (getpalette (if? (inmark?) 9 8))
  2645.       end
  2646.     end
  2647.  
  2648.  
  2649.   object  fmgr
  2650.  
  2651.     // called after a fmgr window is opened and before it's displayed
  2652.     function  onopen
  2653.  
  2654.       // set the window event object
  2655.       setwinobj "fmgr"
  2656.  
  2657.       // check for include picklist
  2658.       if ftype? 'i' then
  2659.         display
  2660.         say "Select file to insert"
  2661.       end
  2662.     end
  2663.  
  2664.  
  2665.   // all windows
  2666.   object  a
  2667.  
  2668.     // called when sounding an alarm
  2669.     // (allows you to customize the alarm sound)
  2670.     function  onalarm
  2671.       beep 750 70
  2672.     end
  2673.  
  2674.     // get default comments for a filename (c1, c2 passed by reference)
  2675.     // (associates a filename with comment symbols)
  2676.     function  oncomment (file c1 c2)
  2677.       case getext (upcase file)
  2678.         when ".C", ".AML"   c1 = "//"
  2679.         when ".ASM"         c1 = ';'
  2680.         when ".PAS"         c1 = '{'   c2 = '}'
  2681.         otherwise           c1 = '>'
  2682.       end
  2683.     end
  2684.  
  2685.  
  2686.     // called when entering the editor before any windows are open. DOS
  2687.     // command-line filespecs are passed to this function
  2688.     function  onentry
  2689.  
  2690.       // save the DOS entry path
  2691.       _cp = getcurrpath
  2692.  
  2693.       // open prompt and window history
  2694.       if _SaveHistory == 'y' then
  2695.         openhistory (bootpath "history.dat")
  2696.       end
  2697.  
  2698.       // process command-line parameters passed to the editor
  2699.       param_num = 1
  2700.       parameter = arg 1
  2701.  
  2702.       while parameter do
  2703.  
  2704.         // check for command line options
  2705.         if parameter [1:2] == "-e"  then
  2706.           queue parameter [3 : TO_END]
  2707.  
  2708.         // open files/directories
  2709.         else
  2710.           open parameter
  2711.         end
  2712.  
  2713.         // next command line parm
  2714.         param_num = param_num + 1
  2715.         parameter = arg param_num
  2716.       end
  2717.  
  2718.       // still no windows open? then do bootoptions...
  2719.       if not getcurrwin then
  2720.         case _BootOpt
  2721.           when 'd'  restoredesk
  2722.           when 'f'  open '.'
  2723.           when 'n'  opennew
  2724.           otherwise
  2725.             filespec = ask "File or Directory" "_load"
  2726.             if filespec then
  2727.               open filespec
  2728.             else
  2729.               halt
  2730.             end
  2731.         end
  2732.       end
  2733.  
  2734.       // initialize the mouse
  2735.       if _Mouse == 'y' then
  2736.         if openmouse _MouseOpt then
  2737.           mousepos  15999 + getvidcols  15999 + getvidrows
  2738.           y_sens = _MouSenY
  2739.           if (getos 'v') > 9 then
  2740.             mousesense (_MouSenX * 5) / 8  (y_sens * 5) / 8  _MouDST
  2741.           else
  2742.             mousesense _MouSenX y_sens _MouDST
  2743.           end
  2744.         end
  2745.       end
  2746.  
  2747.       // open key macros if configured
  2748.       if _SaveMac == 'y' then
  2749.         openkey (bootpath "a.mac")
  2750.       end
  2751.  
  2752.       // set autosave timer
  2753.       send "autosave" _AutoSave
  2754.     end
  2755.  
  2756.  
  2757.     // called when exiting the editor after all windows are closed
  2758.     function  onexit
  2759.  
  2760.       // open prompt on non-global exit (if configured)
  2761.       if not __G then
  2762.         if _ExitOpen == 'y' then
  2763.           filespec = ask "File or Directory" "_load"
  2764.           if filespec then
  2765.             open filespec
  2766.           end
  2767.         end
  2768.       end
  2769.  
  2770.       // final exit if no windows open
  2771.       if not getcurrwin then
  2772.  
  2773.         // save prompt and window history
  2774.         if _SaveHistory == 'y' then
  2775.           savehistory (bootpath "history.dat")
  2776.         end
  2777.  
  2778.         // save key macros if configured
  2779.         if _SaveMac == 'y' then
  2780.           // check if record occurred
  2781.           if lookup "kd" "mon" then
  2782.             savekey (bootpath "a.mac")
  2783.           end
  2784.         end
  2785.  
  2786.         // restore entry path saved in onentry
  2787.         currpath _cp
  2788.  
  2789.         closemouse
  2790.         halt
  2791.       end
  2792.     end
  2793.  
  2794.